From 260c78469225b08e25b81cffa565d6d8e167b6cf Mon Sep 17 00:00:00 2001 From: robertlipe Date: Sun, 30 Oct 2011 19:38:45 +0000 Subject: [PATCH] Don't blow out whitespace in GPX writer on unknown tags. --- gpsbabel/gpx.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index 06fb24ccb..55413910d 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -1454,7 +1454,6 @@ fprint_tag_and_attrs(const char* prefix, const char* suffix, xml_tag* tag) static void fprint_xml_chain(xml_tag* tag, const waypoint* wpt) { - char* tmp_ent; while (tag) { if (!tag->cdata && !tag->child) { fprint_tag_and_attrs("<", " />", tag); @@ -1462,6 +1461,7 @@ fprint_xml_chain(xml_tag* tag, const waypoint* wpt) fprint_tag_and_attrs("<", ">", tag); if (tag->cdata) { + char* tmp_ent; tmp_ent = xml_entitize(tag->cdata); gbfprintf(ofd, "%s", tmp_ent); xfree(tmp_ent); @@ -1477,9 +1477,16 @@ fprint_xml_chain(xml_tag* tag, const waypoint* wpt) gbfprintf(ofd, "\n", tag->tagname); } if (tag->parentcdata) { - tmp_ent = xml_entitize(tag->parentcdata); + // retain whitespacing, but nuke leading NL as the above will add a trailing. + + char* otmp_ent, *tmp_ent = NULL; + otmp_ent = xml_entitize(tag->parentcdata); + if (otmp_ent[0] == '\n') + tmp_ent = otmp_ent+1; + else + tmp_ent = otmp_ent; gbfprintf(ofd, "%s", tmp_ent); - xfree(tmp_ent); + xfree(otmp_ent); } tag = tag->sibling; } -- 2.30.2